import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import _ from 'lodash' //lodash工具库
import {request,jsonp} from './util/request.js' //axios封装
import util from './util'

//全量引入Element-UI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

import Crumbs from './components/project/Crumbs.vue'
import Result from './components/project/Result.vue'
Vue.component('Crumbs', Crumbs)
Vue.component('Result', Result)

Vue.config.productionTip = false
Vue.prototype.$http = request; //普通http请求
Vue.prototype.$jsonp = jsonp; //jsonp请求
Vue.prototype.$_ = _; //lodash核心对象
Vue.prototype.$util = util; //业务相关util


/**
 * 解决浏览器sessionStorage在新打开tab页无法共享的BUG
 * BUG编号281
 */
(function() {
	if (!sessionStorage.length) {
		// 这个调用能触发目标事件，从而达到共享数据的目的
		localStorage.setItem('emitOrigin', Date.now());
	}
	// 该事件是核心
	window.addEventListener('storage', function(event) {
		if (event.key == 'emitOrigin') {
			// 已存在的标签页会收到这个事件
			localStorage.setItem('emitTab', JSON.stringify(sessionStorage));
			localStorage.removeItem('emitTab');
		} else if (event.key == 'emitTab' && !sessionStorage.length) {
			// 新开启的标签页会收到这个事件
			let data = JSON.parse(event.newValue);
			for (key in data) {
				sessionStorage.setItem(key, data[key]);
			}
		}
	});
})();

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')


